<template>
  <div>
    <div class="statistics-container">

      <div class="">
        <div>
          <el-button v-if="isZJC" type="primary" @click="benginNew()">开启一个测试流程</el-button>
        </div>
        <div><h1>主页</h1></div>
      </div>
      <div class="stat-item">
        <div class="stat-value">{{ statisticVo.myApplyNum }}</div>
        <div class="stat-label">我的申请</div>
      </div>
      <div class="stat-item">
        <div class="stat-value">{{ statisticVo.myToDoNum }}</div>
        <div class="stat-label">我的待办</div>
      </div>
      <div class="stat-item">
        <div class="stat-value">{{ statisticVo.myApprovedNumber }}</div>
        <div class="stat-label">我的已办</div>
      </div>
    </div>
  </div>
</template>

<script>
import request from "@/request/request";
import {ElMessage} from "element-plus";

export default {
  props: {
    isZJC: Boolean
  },
  name: "StatisticsComponent",
  data() {
    return {
      statisticVo: {
        myToDoNum: 0,
        myApprovedNumber: 0,
        myApplyNum: 0,
      }
    };
  },
  created() {
    request.get("/approveInfo/statistics")
        .then((response) => {
          if (response.code === 200) {
            this.statisticVo = response.data;
            console.log(response.data)
            console.log(this.statisticVo)
          } else {
            ElMessage.error(response.msg);
          }
        });
  }, methods: {
    benginNew() {
      const requestData = {
        processCode: "test",
        processData: {
          desc: "测试描述",
          title: "测试题目"
        }
      };

      request
          .post('/testAddTitle', requestData)
          .then((response) => {
            if (response.data.code === 200) {
              ElMessage.success('开启成功');
              this.loadData()
            } else {
              ElMessage.error(response.msg);
            }
          })
    }
  }
};
</script>

<style scoped>
.statistics-container {
  display: flex;
  justify-content: space-around;
  background-color: #ffffff;
  padding: 50px;
  border-radius: 5px;
  margin-bottom: 30px;
}

.stat-item {
  text-align: center;
  padding: 20px;
  border: 1px solid #ccc;
  border-radius: 5px;
}

.stat-value {
  font-size: 24px;
  font-weight: bold;
}

.stat-label {
  margin-top: 5px;
  font-size: 14px;
  color: #888;
}
</style>
